from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from .models import Order, Cart, OrderDeta


class OrderSer(ModelSerializer):
    class Meta:
        model = Order
        fields = '__all__'


class CartSer(ModelSerializer):
    good = serializers.SerializerMethodField()

    def get_good(self, obj):
        return {'name': obj.goods.name, 'price': obj.goods.price, 'image': obj.goods.image}

    class Meta:
        model = Cart
        fields = '__all__'


class OrderDetaSer(ModelSerializer):
    class Meta:
        model = OrderDeta
        fields = '__all__'
